package org.flexspeedup.blog.controllers
{
import org.flexspeedup.blog.controllers.IApplicationController;
import org.flexspeedup.blog.models.IApplicationModel;
import org.flexspeedup.blog.events.NotifyChangeEvent;
import org.flexspeedup.blog.events.RemovePendingChangesEvent;
import org.flexspeedup.blog.events.NavigateToEvent;

/**
 * High level application tasks
 */
public class ApplicationController implements IApplicationController
{
    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new instance of this class.
     */
    public function ApplicationController()
    {
    }

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    // applicationModel
    //----------------------------------
    [Inject(source="applicationModel")]
    /**
     * applicationModel bean
     */
    public var applicationModel:IApplicationModel;
    
    //--------------------------------------------------------------------------
    //
    //  Methods - Mediators
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  navigateTo
    //----------------------------------
    [Mediate(event="NavigateToEvent.ID", properties="section")]
    /**
     * Navigates to a section in the site
     */
    public function navigateTo(section:String):void
    {
        NavigateToEvent;
        if (applicationModel.hasPendingChanges)
        {
            // handle pending changes
        }
        applicationModel.currentState = section;
    }
    
    //----------------------------------
    //  notifyChange
    //----------------------------------
    [Mediate(event="NotifyChangeEvent.ID")]
    /**
     * Marks the app as changed
     */
    public function notifyChange():void
    {
        NotifyChangeEvent;
        applicationModel.hasPendingChanges = true;   
    }
    
    //----------------------------------
    //  removePendingChanges
    //----------------------------------
    [Mediate(event="RemovePendingChangesEvent.ID")]
    /**
     * Removes all pending changes
     */
    public function removePendingChanges():void
    {   
        RemovePendingChangesEvent;
        applicationModel.hasPendingChanges = false;   
    }

}
}